home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Goodies / 3rd Party Demos / 3rd Party Plugins / Multimedia / AudioCDPlug / Read Me AudioCDPlug
Encoding:
Text File  |  1999-07-23  |  6.9 KB  |  187 lines

  1. AudioCDPlug 1.0
  2. By Christoph Cantillon - Azine Software
  3. http://azinesw.hypermart.net/ (Please click the top banner)
  4. mailto: azinenet@kagi.com
  5. Many thanks to: Glenn R. Howes
  6.  
  7. What is AudioCDPlug 1.0?
  8. It is a plugin for RealBasic (1.x and 2.x) that gives you control over your audio cd drive(s). This plugin has been made with the help of Glenn R. Howes' source code for AudioCDgh, a fine AppleScript OSAX for controlling AudioCD playback.
  9.  
  10. Legal mumbo-jumbo
  11. If you want to use this plugin in any project, wether commercial, freeware, shareware, postcardware, public domain,..., you must tell me first. You don't even have to wait for a reply, you can use it for free, as long as I'm aware of it. Just so I know how popular it is.
  12.  
  13. How do I use it?
  14. To install it you just drop it on the 'Plugins' folder in the same folder as RealBasic (you may have to create this folder first).
  15.  
  16. Here is a list of the commands and descriptions of them:
  17.  
  18.     "CountAudioDrives as Integer"
  19. This returns the number of CD-ROM drives connected to your computer. For some reason you must call this first before using the AudioCDPlug, but only once.
  20.  
  21.     "GetAudioDriveRefNum (n as Integer) as Integer"
  22. This returns the Reference Number of the n-th CD-ROM drive (0 is first). You need this number to use the other methods.
  23.  
  24.     "PlayAudioCD (refnum as Integer, starttime as Integer, endtime as Integer) as Integer"
  25. This starts playing the CD in the drive specified by 'refnum' from starttime to endtime. Starttime and endtime are relative to the beginning of the CD, not the beginning of the first track. You must know where track 1 begins. I might want to add this feature in the future, but I am not sure yet, I always use PlayAudioCDTrack. Most AudioCDs start at 768.
  26. For more information about the time integers, read chapter 'About time'.
  27.  
  28.     "PlayAudioCDTrack (refnum as Integer, track as Integer) as Integer"
  29. This will play track number 'track' with drive 'refnum'.
  30.  
  31.     "StopAudioCD (refnum as Integer) as Integer"
  32. This will stop playing drive 'refnum'.
  33.  
  34.     "GetAudioCDVolume (refnum as Integer, channel as Integer) as Integer"
  35. This returns the level of a specified channel (channel) of a specific drive (refnum). Maximum is 255, minimum is 0.
  36. If the result is negative, something went wrong. There are two channels 0 and 1, one for left, and one for right. But I don't know which one is left or which one is right. (Sorry)
  37.  
  38.     "SetAudioCDVolume (refnum as Integer, channel as Integer, volume as Integer) as Integer"
  39. This changes the level of a specific channel (channel) of a specific drive (refnum) to a specific value (volume). There are two channels 0 and 1, one for left, and one for right. But I don't know which one is left or which one is right. (Sorry)
  40.  
  41.     "EjectCD (refnum as Integer) as Integer"
  42. This ejects the CD in drive refnum, or opens the tray if it's empty.
  43.  
  44.     "PauseAudioCD (refnum as Integer) as Integer"
  45. This pauses playback in drive refnum.
  46.  
  47.     "ResumeAudioCD (refnum as Integer) as Integer"
  48. This resumes paused playback in drive refnum.
  49.  
  50.     "GetAudioCDTrack (refnum as Integer) as Integer"
  51. This returns the currently playing track in drive refnum.
  52.  
  53.     "GetAudioCDState (refnum as Integer) as Integer"
  54. This returns the state of drive refnum.
  55.  0 - Playing
  56.  1 - Paused
  57.  2 - Muted (?)
  58.  3 - Finished
  59.  4 - Error
  60.  5 - Stopped
  61. Any other value is an error code.
  62.  
  63.     "GetCDTrackTime (refnum as Integer) as Integer"
  64. Returns the time since the beginning of the current track of drive refnum.
  65.  
  66.     "CountCDTracks (refnum as Integer) as Integer"
  67. This counts the number of CD tracks on the cd in drive refnum. This also counts non-audio tracks. To count only the audio-tracks, use CountAudioCDTracks.
  68.  
  69.     "GetCDTotalTime (refnum as Integer) as Integer"
  70. Returns the time since the beginning of the cd in drive refnum.
  71.  
  72.     "ResumeAudioCDAt (refnum as Integer, time as Integer) as Integer"
  73. This will make the cd in drive 'refnum' jump to a specified time.
  74.  
  75.     "CountCDAudioTracks (refnum as Integer) as Integer"
  76. This returns the number of audio tracks on the cd in drive 'refnum'. Data tracks are EXCLUDED. If you want to count data-tracks also, use CountCDTracks.
  77.  
  78.     "IsAudioCDTrack (refnum as Integer, tracknumber as Integer) as Boolean"
  79. Checks if track 'tracknumber' on the disc in drive 'refnum' is an AudioCD track.
  80.  
  81.     "GetAudioCDTrackLength (refnum as Integer, tracknumber as Integer) as Integer"
  82. Returns the length of a specified track (tracknumber) in drive (refnum). 1 is first track.
  83.  
  84. AboutTime
  85. Time is returned as a 'long', thus 4 bytes big. The first byte has no meaning, the second one are the minutes, the third are seconds and the fourth are 'frames' (75 in one second, I believe).
  86. Here's an example of how to convert from this value to minutes, seconds and frames:
  87.  
  88. DIM CDtime,temp,i,x as Integer
  89. DIM houre,minute,frame as Integer
  90. DIM refnum,drivecount as Integer
  91.  
  92. drivecount = CountAudioDrives()
  93. refnum = GetAudioDriveRefnum(0)
  94.  
  95. CDtime = GetAudioCDTrackLength(refnum,1)
  96.  
  97. realtime = New Date
  98.  
  99. realtime.year = 1904
  100. realtime.month = 1
  101. realtime.day = 1
  102. realtime.houre = 0
  103.  
  104. For i = 2 to 4
  105.   temp = CDtime
  106.   CDTime = (floor(CDtime/256))*256
  107.   x = temp - CDTime
  108.   Select case i
  109.   Case 2
  110.     minute = x
  111.   Case 3
  112.     second = x
  113.   Case 4
  114.     frame = x
  115. Next i
  116.  
  117. msgbox "The lenght of track 1 is "+str(minute)+" minutes, "+str(second)+" seconds, and "+str(frame)+" frames."
  118.  
  119. To work the other way around, try this:
  120.  
  121. DIM CDtime as Integer
  122. DIM minute,second,frame as Integer
  123.  
  124. CDTime = (minute * 256 + second) * 256 + frame
  125.  
  126. Error codes
  127. I haven't figured out all error codes myself. I can give you these however:
  128. -65532 - Data disc without audio tracks (I think)
  129. -65530 - No disc
  130. -50 - Invalid start/endtime.
  131. -22 - AudioCDPlug not initialized (I think). You forgot to do a CountAudioDrives().
  132. (They are all negative, ie below zero)
  133.  
  134. Demonstration
  135.  
  136. DIM refnum,drivecount,error,track,tt as Integer
  137.  
  138. drivecount = CountAudioDrives()
  139. refnum = drivecount - 1  // Get the last drive
  140.  
  141. For track = 1 to CountCDAudioTracks(refnum)
  142.   If IsAudioCDTrack(refnum,track) then
  143.     exit
  144.   End if
  145. Next
  146.  
  147. error = PlayAudioCDTrack(refnum,track)
  148.  
  149. if error <> then
  150.   beep
  151.   msgbox "An error occured. Type : "+str(error)
  152. else
  153.   tt = ticks
  154.   while tt < ticks + 600
  155.   wend
  156.   error = PauseAudioCD(refnum)
  157.   if error <> then
  158.     beep
  159.     msgbox "An error occured. Type : "+str(error)
  160.   else
  161.     tt = ticks
  162.     while tt < ticks + 180
  163.     wend
  164.     error = ResumeAudioCD(refnum)
  165.     if error <> then
  166.       beep
  167.       msgbox "An error occured. Type : "+str(error)
  168.     else
  169.       tt = ticks
  170.       while tt < ticks + 180
  171.       wend
  172.       error = StopAudioCD(refnum)
  173.       if error <> then
  174.         beep
  175.         msgbox "An error occured. Type : "+str(error)
  176.       else
  177.         error = EjectCD(refnum)
  178.         if error <> then
  179.           beep
  180.           msgbox "An error occured. Type : "+str(error)
  181.         end if
  182.       end if
  183.     end if
  184.   end if
  185. end if
  186.  
  187. This plays the first 10 seconds, then pauses, waits 3 seconds, resumes and plays another 3 seconds. Then it stops and ejects the disc. I hope this makes everything clear.